PyCon 2014 - The GRAMMY goes to...Python

Carol Willing, FabLab San Diego

Getting Started with music21


In [1]:
from music21 import *

In [2]:
# ignore this - just sets up inline display of output
%load_ext music21.ipython21.ipExtension

Short melody in musical notation


In [21]:
converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#").show()


Out[21]:

In [4]:
print (serial.rowToMatrix([2,1,9,10,5,3,4,0,8,7,6,11]) )


  0 11  7  8  3  1  2 10  6  5  4  9
  1  0  8  9  4  2  3 11  7  6  5 10
  5  4  0  1  8  6  7  3 11 10  9  2
  4  3 11  0  7  5  6  2 10  9  8  1
  9  8  4  5  0 10 11  7  3  2  1  6
 11 10  6  7  2  0  1  9  5  4  3  8
 10  9  5  6  1 11  0  8  4  3  2  7
  2  1  9 10  5  3  4  0  8  7  6 11
  6  5  1  2  9  7  8  4  0 11 10  3
  7  6  2  3 10  8  9  5  1  0 11  4
  8  7  3  4 11  9 10  6  2  1  0  5
  3  2 10 11  6  4  5  1  9  8  7  0


In [5]:
print (serial.getHistoricalRowByName('RowSchoenbergOp37').matrix() )


  0  B  7  8  3  1  2  A  6  5  4  9
  1  0  8  9  4  2  3  B  7  6  5  A
  5  4  0  1  8  6  7  3  B  A  9  2
  4  3  B  0  7  5  6  2  A  9  8  1
  9  8  4  5  0  A  B  7  3  2  1  6
  B  A  6  7  2  0  1  9  5  4  3  8
  A  9  5  6  1  B  0  8  4  3  2  7
  2  1  9  A  5  3  4  0  8  7  6  B
  6  5  1  2  9  7  8  4  0  B  A  3
  7  6  2  3  A  8  9  5  1  0  B  4
  8  7  3  4  B  9  A  6  2  1  0  5
  3  2  A  B  6  4  5  1  9  8  7  0

Convert from kern format to MusicXML


In [24]:
c = converter.parse('/Users/carol/Downloads/duet/edokomuri.krn')
c.show('musicxml')

Translate to Braille and Display

Reading from a corpus


In [7]:
sBach = corpus.parse('bach/bwv7.7')
sBach.show()


Out[7]:

In [23]:
sBach.show('braille')

Graphing and Plotting


In [9]:
graph.plotStream(sBach)



In [10]:
graph.plotStream(sBach, 'PlotHistogramPitchClass')



In [11]:
haydn = corpus.parse('haydn/symphony94/02')
plot = graph.PlotDolan(haydn)
plot.process()



In [35]: